package logic

import (
	"context"
	"shop/shoprpc/shoprpc"

	"shop/api/internal/svc"
	"shop/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserPwdUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserPwdUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserPwdUpdateLogic {
	return &UserPwdUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserPwdUpdateLogic) UserPwdUpdate(req *types.UserPwdUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	pwdupdate, err := l.svcCtx.ShopRpc.UserPwdUpdate(l.ctx, &shoprpc.UserPwdUpdateRequest{
		Userid:       req.Userid,
		Tel:          req.Tel,
		Smscode:      req.Smscode,
		Newpassword:  req.Newpassword,
		Surepassword: req.Surepassword,
	})
	if err != nil {
		return &types.Response{
			Code:    0,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "用户密码修改成功",
		Data:    pwdupdate,
	}, nil
}
